//
//  AXHomeZxktSecondCell.m
//  AnXin100
//
//  Created by 天质弘耕 on 2018/10/23.
//  Copyright © 2018年 tzhg. All rights reserved.
//

#import "AXHomeZxktSecondCell.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "UITableView+SDAutoTableViewCellHeight.h"


@interface AXHomeZxktSecondCell ()

@end
@implementation AXHomeZxktSecondCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self creatView];
        [self setlayout];
    }
    return self;
}

- (void)creatView {
   
  
    /** 产品图片 */
    self.productImageView = [[UIImageView alloc]init];
    self.productImageView.userInteractionEnabled = YES;
    self.productImageView.image = [UIImage imageNamed:@"zxkt_cpbf"];
    [self.contentView addSubview:self.productImageView];
    /** 添加手势 */
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    [self.productImageView addGestureRecognizer:tap];
    
    
    /** 产品名字 */
    self.productNameLabel = [[UILabel alloc]init];
    self.productNameLabel.text = @"草莓种植技术";
    self.productNameLabel.font = FONT_FOURTEEN;;
    self.productNameLabel.numberOfLines = 2;
    self.productNameLabel.textColor = COLOR_DIV;
    [self.contentView addSubview:self.productNameLabel];
    /** 老师 */
    self.teacherLabel = [[UILabel alloc]init];
    self.teacherLabel.textColor = [UIColor colorWithHex:0x666666];
    self.teacherLabel.font = FONT_TWELVE;
    self.teacherLabel.text = @"王老师";
    [self.contentView addSubview:self.teacherLabel];
    
   
    /** 时间 */
    self.startTimeLabel = [[UILabel alloc]init];
    self.startTimeLabel.textColor = COLOR_ORG;
    self.startTimeLabel.font = FONT_EIGHTEEN;
    /** 富文本 */
    NSMutableAttributedString  *timeString = [[  NSMutableAttributedString  alloc]init];
    NSAttributedString *timeStr = [[ NSAttributedString alloc]initWithString:@"开课时间: " attributes:@{NSFontAttributeName:FONT_TWELVE,NSForegroundColorAttributeName:COLOR_DIV}];
    [timeString appendAttributedString:timeStr];
    
    NSAttributedString *str2 = [[ NSAttributedString alloc]initWithString:@"2018.10.21" attributes:@{NSFontAttributeName:FONT_TWELVE,NSForegroundColorAttributeName:COLOR_ORG}];
    [timeString appendAttributedString:str2];
    
    self.startTimeLabel.attributedText = timeString;//把字符串加到prepareLessonLabel上
    [self.contentView addSubview:self.startTimeLabel];
}

- (void)setlayout {
   
    /* 产品图片 **/
    self.productImageView.sd_layout
    .leftSpaceToView(self.contentView, 10)
    .topSpaceToView(self.contentView, 0)
    .widthIs(100)
    .heightIs(100);
    /** 产品名字 */
    self.productNameLabel.sd_layout
    .leftSpaceToView(self.productImageView, 10)
    .topSpaceToView(self.contentView, 10)
    .rightSpaceToView(self.contentView, 10)
    .heightIs(40);
    /* 老师 **/
    self.teacherLabel.sd_layout
    .leftEqualToView(self.productNameLabel)
    .rightSpaceToView(self.contentView, 10)
    .topSpaceToView(self.productNameLabel, 0)
    .heightIs(30);
    /* 时间 **/
    self.startTimeLabel.sd_layout
    .leftSpaceToView(self.productImageView, 10)
    .topSpaceToView(self.teacherLabel, 0)
    .rightSpaceToView(self.contentView, 10)
    .heightIs(30);
    

    
    /** cell高度自适应第一步 */
    [self setupAutoHeightWithBottomView:self.startTimeLabel bottomMargin:10];
    
}


#pragma mark - action

- (void)tap:(UITapGestureRecognizer *)gesture {
    
    if (self.tapButtonClickedBlock) {
        self.tapButtonClickedBlock(gesture.view.tag);
    }
}



@end
